package FileWork;

import java.io.File;
import java.io.FileFilter;

/*列出当前目录中所有名字包含s的子项，匿名内部类写法*/
public class Test06s {
    public static void main(String[] args) {
        File file = new File(".");
        if (file.isDirectory()){
            FileFilter filter = new FileFilter() {
                @Override
                public boolean accept(File pathname) {
                    String name = pathname.getName();

                    boolean x ;
                    if(name.indexOf("s")!= -1){
                        x =true;
                    }else {
                        x = false;
                    }
                    return x;
//                    return name.contains("s");
                }
            };
            File[] subs = file.listFiles(filter);
            for (File sub:subs){
                System.out.println(sub.getName());
            }
        }
    }
}
